﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace HK.Core.Extend
{
    public static class EnumerableEx
    {
        public static IOrderedEnumerable<T> Order<T, TKey>(this IEnumerable<T> iSource, Func<T, TKey> iSelector, bool iAscending)
        {
            if (iAscending)
            {
                return iSource.OrderBy(iSelector);
            }

            return iSource.OrderByDescending(iSelector);
        }

        public static IOrderedEnumerable<T> ThenBy<T, TKey>(this IOrderedEnumerable<T> iSource, Func<T, TKey> iSelector, bool iAscending)
        {
            if (iAscending)
            {
                return iSource.ThenBy(iSelector);
            }

            return iSource.ThenByDescending(iSelector);
        }
    }
}
